<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0" name="viewport">

  <title>Statistics os Costco sale in Hangzhou </title>
  <meta content="" name="description">
  <meta content="" name="keywords">
  <script src="https://cdn.bootcdn.net/ajax/libs/angular.js/1.8.3/angular.js"></script>
  <script src="assets/vendor/echarts/echarts.min.js"></script>

  <!-- Favicons -->
  <link href="assets/img/favicon.png" rel="icon">
  <link href="assets/img/apple-touch-icon.png" rel="apple-touch-icon">


  <!-- Google Fonts -->
  <link href="https://fonts.gstatic.com" rel="preconnect">
  <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Nunito:300,300i,400,400i,600,600i,700,700i|Poppins:300,300i,400,400i,500,500i,600,600i,700,700i" rel="stylesheet">

  <!-- Vendor CSS Files -->
  <link href="assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
  <link href="assets/vendor/bootstrap-icons/bootstrap-icons.css" rel="stylesheet">
  <link href="assets/vendor/boxicons/css/boxicons.min.css" rel="stylesheet">
  <link href="assets/vendor/quill/quill.snow.css" rel="stylesheet">
  <link href="assets/vendor/quill/quill.bubble.css" rel="stylesheet">
  <link href="assets/vendor/remixicon/remixicon.css" rel="stylesheet">
  <link href="assets/vendor/simple-datatables/style.css" rel="stylesheet">

  <!-- Template Main CSS File -->
  <link href="assets/css/style.css" rel="stylesheet">

  <!-- =======================================================
  * Template Name: NiceAdmin
  * Updated: May 30 2023 with Bootstrap v5.3.0
  * Template URL: https://bootstrapmade.com/nice-admin-bootstrap-admin-html-template/
  * Author: BootstrapMade.com
  * License: https://bootstrapmade.com/license/
  ======================================================== -->
</head>

<body>

  <!-- ======= Header ======= -->
  <header id="header" class="header fixed-top d-flex align-items-center">

    <div class="d-flex align-items-center justify-content-between">
      <a href="index.html" class="logo d-flex align-items-center">
        <img src="assets/img/logo.png" alt="">
        <span class="d-none d-lg-block">NiceAdmin</span>
      </a>
      <i class="bi bi-list toggle-sidebar-btn"></i>
    </div><!-- End Logo -->

    <div class="search-bar">
      <form class="search-form d-flex align-items-center" method="POST" action="#">
        <input type="text" name="query" placeholder="Search" title="Enter search keyword">
        <button type="submit" title="Search"><i class="bi bi-search"></i></button>
      </form>
    </div><!-- End Search Bar -->

    <nav class="header-nav ms-auto">
      <ul class="d-flex align-items-center">

        <li class="nav-item d-block d-lg-none">
          <a class="nav-link nav-icon search-bar-toggle " href="#">
            <i class="bi bi-search"></i>
          </a>
        </li><!-- End Search Icon-->

        <li class="nav-item dropdown">

          <a class="nav-link nav-icon" href="#" data-bs-toggle="dropdown">
            <i class="bi bi-bell"></i>
            <span class="badge bg-primary badge-number">4</span>
          </a><!-- End Notification Icon -->

          <ul class="dropdown-menu dropdown-menu-end dropdown-menu-arrow notifications">
            <li class="dropdown-header">
              You have 4 new notifications
              <a href="#"><span class="badge rounded-pill bg-primary p-2 ms-2">View all</span></a>
            </li>
            <li>
              <hr class="dropdown-divider">
            </li>

            <li class="notification-item">
              <i class="bi bi-exclamation-circle text-warning"></i>
              <div>
                <h4>Lorem Ipsum</h4>
                <p>Quae dolorem earum veritatis oditseno</p>
                <p>30 min. ago</p>
              </div>
            </li>

            <li>
              <hr class="dropdown-divider">
            </li>

            <li class="notification-item">
              <i class="bi bi-x-circle text-danger"></i>
              <div>
                <h4>Atque rerum nesciunt</h4>
                <p>Quae dolorem earum veritatis oditseno</p>
                <p>1 hr. ago</p>
              </div>
            </li>

            <li>
              <hr class="dropdown-divider">
            </li>

            <li class="notification-item">
              <i class="bi bi-check-circle text-success"></i>
              <div>
                <h4>Sit rerum fuga</h4>
                <p>Quae dolorem earum veritatis oditseno</p>
                <p>2 hrs. ago</p>
              </div>
            </li>

            <li>
              <hr class="dropdown-divider">
            </li>

            <li class="notification-item">
              <i class="bi bi-info-circle text-primary"></i>
              <div>
                <h4>Dicta reprehenderit</h4>
                <p>Quae dolorem earum veritatis oditseno</p>
                <p>4 hrs. ago</p>
              </div>
            </li>

            <li>
              <hr class="dropdown-divider">
            </li>
            <li class="dropdown-footer">
              <a href="#">Show all notifications</a>
            </li>

          </ul><!-- End Notification Dropdown Items -->

        </li><!-- End Notification Nav -->

        <li class="nav-item dropdown">

          <a class="nav-link nav-icon" href="#" data-bs-toggle="dropdown">
            <i class="bi bi-chat-left-text"></i>
            <span class="badge bg-success badge-number">3</span>
          </a><!-- End Messages Icon -->

          <ul class="dropdown-menu dropdown-menu-end dropdown-menu-arrow messages">
            <li class="dropdown-header">
              You have 3 new messages
              <a href="#"><span class="badge rounded-pill bg-primary p-2 ms-2">View all</span></a>
            </li>
            <li>
              <hr class="dropdown-divider">
            </li>

            <li class="message-item">
              <a href="#">
                <img src="assets/img/messages-1.jpg" alt="" class="rounded-circle">
                <div>
                  <h4>Maria Hudson</h4>
                  <p>Velit asperiores et ducimus soluta repudiandae labore officia est ut...</p>
                  <p>4 hrs. ago</p>
                </div>
              </a>
            </li>
            <li>
              <hr class="dropdown-divider">
            </li>

            <li class="message-item">
              <a href="#">
                <img src="assets/img/messages-2.jpg" alt="" class="rounded-circle">
                <div>
                  <h4>Anna Nelson</h4>
                  <p>Velit asperiores et ducimus soluta repudiandae labore officia est ut...</p>
                  <p>6 hrs. ago</p>
                </div>
              </a>
            </li>
            <li>
              <hr class="dropdown-divider">
            </li>

            <li class="message-item">
              <a href="#">
                <img src="assets/img/messages-3.jpg" alt="" class="rounded-circle">
                <div>
                  <h4>David Muldon</h4>
                  <p>Velit asperiores et ducimus soluta repudiandae labore officia est ut...</p>
                  <p>8 hrs. ago</p>
                </div>
              </a>
            </li>
            <li>
              <hr class="dropdown-divider">
            </li>

            <li class="dropdown-footer">
              <a href="#">Show all messages</a>
            </li>

          </ul><!-- End Messages Dropdown Items -->

        </li><!-- End Messages Nav -->

        <li class="nav-item dropdown pe-3">

          <a class="nav-link nav-profile d-flex align-items-center pe-0" href="#" data-bs-toggle="dropdown">
            <img src="assets/img/profile-img.jpg" alt="Profile" class="rounded-circle">
            <span class="d-none d-md-block dropdown-toggle ps-2">K. Anderson</span>
          </a><!-- End Profile Iamge Icon -->

          <ul class="dropdown-menu dropdown-menu-end dropdown-menu-arrow profile">
            <li class="dropdown-header">
              <h6>Kevin Anderson</h6>
              <span>Web Designer</span>
            </li>
            <li>
              <hr class="dropdown-divider">
            </li>

            <li>
              <a class="dropdown-item d-flex align-items-center" href="users-profile.html">
                <i class="bi bi-person"></i>
                <span>My Profile</span>
              </a>
            </li>
            <li>
              <hr class="dropdown-divider">
            </li>

            <li>
              <a class="dropdown-item d-flex align-items-center" href="users-profile.html">
                <i class="bi bi-gear"></i>
                <span>Account Settings</span>
              </a>
            </li>
            <li>
              <hr class="dropdown-divider">
            </li>

            <li>
              <a class="dropdown-item d-flex align-items-center" href="pages-faq.html">
                <i class="bi bi-question-circle"></i>
                <span>Need Help?</span>
              </a>
            </li>
            <li>
              <hr class="dropdown-divider">
            </li>

            <li>
              <a class="dropdown-item d-flex align-items-center" href="#">
                <i class="bi bi-box-arrow-right"></i>
                <span>Sign Out</span>
              </a>
            </li>

          </ul><!-- End Profile Dropdown Items -->
        </li><!-- End Profile Nav -->

      </ul>
    </nav><!-- End Icons Navigation -->

  </header><!-- End Header -->

  <!-- ======= Sidebar ======= -->
  <aside id="sidebar" class="sidebar">

    <ul class="sidebar-nav" id="sidebar-nav">

      <li class="nav-item">
        <a class="nav-link " href="index.html">
          <i class="bi bi-grid"></i>
          <span>销售数据</span>
        </a>
      </li><!-- End Dashboard Nav -->

      <li class="nav-item">
        <a class="nav-link collapsed" data-bs-target="#components-nav" data-bs-toggle="collapse" href="#">
          <i class="bi bi-menu-button-wide"></i><span>Components</span><i class="bi bi-chevron-down ms-auto"></i>
        </a>
        <ul id="components-nav" class="nav-content collapse " data-bs-parent="#sidebar-nav">
          <li>
            <a href="components-alerts.html">
              <i class="bi bi-circle"></i><span>Alerts</span>
            </a>
          </li>
          <li>
            <a href="components-accordion.html">
              <i class="bi bi-circle"></i><span>Accordion</span>
            </a>
          </li>
          <li>
            <a href="components-badges.html">
              <i class="bi bi-circle"></i><span>Badges</span>
            </a>
          </li>
          <li>
            <a href="components-breadcrumbs.html">
              <i class="bi bi-circle"></i><span>Breadcrumbs</span>
            </a>
          </li>
          <li>
            <a href="components-buttons.html">
              <i class="bi bi-circle"></i><span>Buttons</span>
            </a>
          </li>
          <li>
            <a href="components-cards.html">
              <i class="bi bi-circle"></i><span>Cards</span>
            </a>
          </li>
          <li>
            <a href="components-carousel.html">
              <i class="bi bi-circle"></i><span>Carousel</span>
            </a>
          </li>
          <li>
            <a href="components-list-group.html">
              <i class="bi bi-circle"></i><span>List group</span>
            </a>
          </li>
          <li>
            <a href="components-modal.html">
              <i class="bi bi-circle"></i><span>Modal</span>
            </a>
          </li>
          <li>
            <a href="components-tabs.html">
              <i class="bi bi-circle"></i><span>Tabs</span>
            </a>
          </li>
          <li>
            <a href="components-pagination.html">
              <i class="bi bi-circle"></i><span>Pagination</span>
            </a>
          </li>
          <li>
            <a href="components-progress.html">
              <i class="bi bi-circle"></i><span>Progress</span>
            </a>
          </li>
          <li>
            <a href="components-spinners.html">
              <i class="bi bi-circle"></i><span>Spinners</span>
            </a>
          </li>
          <li>
            <a href="components-tooltips.html">
              <i class="bi bi-circle"></i><span>Tooltips</span>
            </a>
          </li>
        </ul>
      </li><!-- End Components Nav -->

      <li class="nav-item">
        <a class="nav-link collapsed" data-bs-target="#forms-nav" data-bs-toggle="collapse" href="#">
          <i class="bi bi-journal-text"></i><span>Forms</span><i class="bi bi-chevron-down ms-auto"></i>
        </a>
        <ul id="forms-nav" class="nav-content collapse " data-bs-parent="#sidebar-nav">
          <li>
            <a href="forms-elements.html">
              <i class="bi bi-circle"></i><span>Form Elements</span>
            </a>
          </li>
          <li>
            <a href="forms-layouts.html">
              <i class="bi bi-circle"></i><span>Form Layouts</span>
            </a>
          </li>
          <li>
            <a href="forms-editors.html">
              <i class="bi bi-circle"></i><span>Form Editors</span>
            </a>
          </li>
          <li>
            <a href="forms-validation.html">
              <i class="bi bi-circle"></i><span>Form Validation</span>
            </a>
          </li>
        </ul>
      </li><!-- End Forms Nav -->

      <li class="nav-item">
        <a class="nav-link collapsed" data-bs-target="#tables-nav" data-bs-toggle="collapse" href="#">
          <i class="bi bi-layout-text-window-reverse"></i><span>Tables</span><i class="bi bi-chevron-down ms-auto"></i>
        </a>
        <ul id="tables-nav" class="nav-content collapse " data-bs-parent="#sidebar-nav">
          <li>
            <a href="tables-general.html">
              <i class="bi bi-circle"></i><span>General Tables</span>
            </a>
          </li>
          <li>
            <a href="tables-data.html">
              <i class="bi bi-circle"></i><span>Data Tables</span>
            </a>
          </li>
        </ul>
      </li><!-- End Tables Nav -->

      <li class="nav-item">
        <a class="nav-link collapsed" data-bs-target="#charts-nav" data-bs-toggle="collapse" href="#">
          <i class="bi bi-bar-chart"></i><span>Charts</span><i class="bi bi-chevron-down ms-auto"></i>
        </a>
        <ul id="charts-nav" class="nav-content collapse " data-bs-parent="#sidebar-nav">
          <li>
            <a href="charts-chartjs.html">
              <i class="bi bi-circle"></i><span>Chart.js</span>
            </a>
          </li>
          <li>
            <a href="charts-apexcharts.html">
              <i class="bi bi-circle"></i><span>ApexCharts</span>
            </a>
          </li>
          <li>
            <a href="charts-echarts.html">
              <i class="bi bi-circle"></i><span>ECharts</span>
            </a>
          </li>
        </ul>
      </li><!-- End Charts Nav -->

      <li class="nav-item">
        <a class="nav-link collapsed" data-bs-target="#icons-nav" data-bs-toggle="collapse" href="#">
          <i class="bi bi-gem"></i><span>Icons</span><i class="bi bi-chevron-down ms-auto"></i>
        </a>
        <ul id="icons-nav" class="nav-content collapse " data-bs-parent="#sidebar-nav">
          <li>
            <a href="icons-bootstrap.html">
              <i class="bi bi-circle"></i><span>Bootstrap Icons</span>
            </a>
          </li>
          <li>
            <a href="icons-remix.html">
              <i class="bi bi-circle"></i><span>Remix Icons</span>
            </a>
          </li>
          <li>
            <a href="icons-boxicons.html">
              <i class="bi bi-circle"></i><span>Boxicons</span>
            </a>
          </li>
        </ul>
      </li><!-- End Icons Nav -->

      <li class="nav-heading">Pages</li>

      <li class="nav-item">
        <a class="nav-link collapsed" href="users-profile.html">
          <i class="bi bi-person"></i>
          <span>Profile</span>
        </a>
      </li><!-- End Profile Page Nav -->

      <li class="nav-item">
        <a class="nav-link collapsed" href="pages-faq.html">
          <i class="bi bi-question-circle"></i>
          <span>F.A.Q</span>
        </a>
      </li><!-- End F.A.Q Page Nav -->

      <li class="nav-item">
        <a class="nav-link collapsed" href="pages-contact.html">
          <i class="bi bi-envelope"></i>
          <span>Contact</span>
        </a>
      </li><!-- End Contact Page Nav -->

      <li class="nav-item">
        <a class="nav-link collapsed" href="pages-register.html">
          <i class="bi bi-card-list"></i>
          <span>Register</span>
        </a>
      </li><!-- End Register Page Nav -->

      <li class="nav-item">
        <a class="nav-link collapsed" href="pages-login.html">
          <i class="bi bi-box-arrow-in-right"></i>
          <span>Login</span>
        </a>
      </li><!-- End Login Page Nav -->

      <li class="nav-item">
        <a class="nav-link collapsed" href="pages-error-404.html">
          <i class="bi bi-dash-circle"></i>
          <span>Error 404</span>
        </a>
      </li><!-- End Error 404 Page Nav -->

      <li class="nav-item">
        <a class="nav-link collapsed" href="pages-blank.html">
          <i class="bi bi-file-earmark"></i>
          <span>Blank</span>
        </a>
      </li><!-- End Blank Page Nav -->

    </ul>

  </aside><!-- End Sidebar-->

  <main id="main" class="main" ng-app="myApp" ng-controller="myCtrl">

    <div class="pagetitle">
      <h1>销售记录</h1>
      <nav>
        <ol class="breadcrumb">
          <li class="breadcrumb-item"><a href="index.html">Costco</a></li>
          <li class="breadcrumb-item active">销售记录</li>
        </ol>
      </nav>
    </div><!-- End Page Title -->

    <section class="section dashboard">
      <div class="row">

        <!-- Left side columns -->
        <div class="col-lg-8">
          <div class="row">

            <!-- Sales Card -->
            <div class="col-xxl-4 col-md-6">
              <div class="card info-card sales-card">

                <div class="filter">
                  <a class="icon" href="#" data-bs-toggle="dropdown"><i class="bi bi-three-dots"></i></a>
                  <ul class="dropdown-menu dropdown-menu-end dropdown-menu-arrow">
                    <li class="dropdown-header text-start">
                      <h6>Filter</h6>
                    </li>

                    <li><a class="dropdown-item" href="#">Today</a></li>
                    <li><a class="dropdown-item" href="#">This Month</a></li>
                    <li><a class="dropdown-item" href="#">This Year</a></li>
                  </ul>
                </div>

                <div class="card-body">
                  <h5 class="card-title">周销量</h5>

                  <div class="d-flex align-items-center">
                    <div class="card-icon rounded-circle d-flex align-items-center justify-content-center">
                      <i class="bi bi-credit-card"></i>
                    </div>
                    <div class="ps-3">
                      <h6 ng-bind="saleWeek">145</h6>
                      <span class="text-success small pt-1 fw-bold" ng-bind="weekInc">12%</span> <span class="text-muted small pt-2 ps-1">同比增长</span>
                    </div>
                  </div>
                </div>

              </div>
            </div>

            <!-- Revenue Card -->
            <div class="col-xxl-4 col-md-6">
              <div class="card info-card revenue-card">

                <div class="filter">
                  <a class="icon" href="#" data-bs-toggle="dropdown"><i class="bi bi-three-dots"></i></a>
                  <ul class="dropdown-menu dropdown-menu-end dropdown-menu-arrow">
                    <li class="dropdown-header text-start">
                      <h6>Filter</h6>
                    </li>

                    <li><a class="dropdown-item" href="#">Today</a></li>
                    <li><a class="dropdown-item" href="#">This Month</a></li>
                    <li><a class="dropdown-item" href="#">This Year</a></li>
                  </ul>
                </div>

                <div class="card-body">
                  <h5 class="card-title">月销量</h5>

                  <div class="d-flex align-items-center">
                    <div class="card-icon rounded-circle d-flex align-items-center justify-content-center">
                      <i class="bi bi-credit-card"></i>
                    </div>
                    <div class="ps-3">
                      <h6 ng-bind="saleMonth">¥3,264</h6>
                      <span class="text-success small pt-1 fw-bold" ng-bind="monthInc">8%</span> <span class="text-muted small pt-2 ps-1">同比增长</span>

                    </div>
                  </div>
                </div>

              </div>
            </div><!-- End Revenue Card -->

            <!-- Customers Card -->
            <div class="col-xxl-4 col-xl-12">

              <div class="card info-card customers-card">

                <div class="filter">
                  <a class="icon" href="#" data-bs-toggle="dropdown"><i class="bi bi-three-dots"></i></a>
                  <ul class="dropdown-menu dropdown-menu-end dropdown-menu-arrow">
                    <li class="dropdown-header text-start">
                      <h6>Filter</h6>
                    </li>

                    <li><a class="dropdown-item" href="#">Today</a></li>
                    <li><a class="dropdown-item" href="#">This Month</a></li>
                    <li><a class="dropdown-item" href="#">This Year</a></li>
                  </ul>
                </div>

                <div class="card-body">
                  <h5 class="card-title">总销量</h5>

                  <div class="d-flex align-items-center">
                    <div class="card-icon rounded-circle d-flex align-items-center justify-content-center">
                      <i class="bi bi-people"></i>
                    </div>
                    <div class="ps-3">
                      <h6 ng-bind="totalSold">31k/10k</h6>
                      <span class="text-danger small pt-1 fw-bold">5%</span> <span class="text-muted small pt-2 ps-1">总进度</span>

                    </div>
                  </div>

                </div>
              </div>

            </div><!-- End Customers Card -->

            <div class="col-12">
              <div class="card">

                <div class="filter">
                  <a class="icon" href="#" data-bs-toggle="dropdown"><i class="bi bi-three-dots"></i></a>
                  <ul class="dropdown-menu dropdown-menu-end dropdown-menu-arrow">
                    <li class="dropdown-header text-start">
                      <h6>Filter</h6>
                    </li>

                    <li><a class="dropdown-item" href="#">Today</a></li>
                    <li><a class="dropdown-item" href="#">This Month</a></li>
                    <li><a class="dropdown-item" href="#">This Year</a></li>
                  </ul>
                </div>

                <div class="card-body">
                  <h5 class="card-title">销量曲线 <span>/近三周</span></h5>

                  <!-- Line Chart -->
                  <div id="reportsChart"></div>

                  <script>
                    var last28DaySold;
                    function renderChart(){
                      new ApexCharts(document.querySelector("#reportsChart"), {
                        series: [{
                          name: '一周前',
                          data: last28DaySold.slice(14, 21)
                        }, {
                          name: '两周前',
                          data: last28DaySold.slice(7, 14)
                        }, {
                          name: '三周前',
                          data: last28DaySold.slice(0, 7)
                        }],
                        chart: {
                          height: 350,
                          type: 'area',
                          toolbar: {
                            show: false
                          },
                        },
                        markers: {
                          size: 4
                        },
                        colors: ['#4154f1', '#2eca6a', '#ff771d'],
                        fill: {
                          type: "gradient",
                          gradient: {
                            shadeIntensity: 1,
                            opacityFrom: 0.3,
                            opacityTo: 0.4,
                            stops: [0, 90, 100]
                          }
                        },
                        dataLabels: {
                          enabled: false
                        },
                        stroke: {
                          curve: 'smooth',
                          width: 2
                        },
                        xaxis: {
                          type: 'date',
                          categories: getLast7DaysOfWeek()
                        },
                        tooltip: {
                          x: {
                            format: 'dd/MM/yy HH:mm'
                          },
                        }
                      }).render();
                    }
                  </script>
                  <!-- End Line Chart -->

                </div>

              </div>
            </div><!-- End Reports -->
<!--            摊点类型销量-->
            <div class="col-12">
              <div class="card">
                <div class="card-body">
                  <h5 class="card-title">摊点类型数据统计</h5>
                  <!-- Line Chart -->
                  <div id="verticalBarChart" style="min-height: 400px;" class="echart"></div>
                  <script>
                    let addressTagCountArr;
                    let verticalBarChartData;

                    function renderVerticalBarChart(){
                      echarts.init(document.querySelector("#verticalBarChart")).setOption({
                        title: {
                          text: '总销量'
                        },
                        tooltip: {
                          trigger: 'axis',
                          axisPointer: {
                            type: 'shadow'
                          }
                        },
                        legend: {},
                        grid: {
                          left: '3%',
                          right: '4%',
                          bottom: '3%',
                          containLabel: true
                        },
                        xAxis: {
                          type: 'value',
                          boundaryGap: [0, 0.01]
                        },
                        yAxis: {
                          type: 'category',
                          data: verticalBarChartData.map(obj=>obj.name)
                        },
                        series: [{
                          // name: '2011',
                          type: 'bar',
                          data: verticalBarChartData.map(obj=>obj.value),
                          label: {
                            show: true, // 显示标签
                            position: "right" // 标签显示在柱形的顶部
                          }
                        }]
                      });
                    }
                  </script>
                  <!-- End Line Chart -->
                </div>
<!--平均-->
                <div id="averageVerticalChart" style="min-height: 400px;" class="echart"></div>
                <script>
                  let averageVerticalChartData;

                  function renderAverageVerticalChart(){
                    echarts.init(document.querySelector("#averageVerticalChart")).setOption({
                      title: {
                        text: '平均出卡数'
                      },
                      tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                          type: 'shadow'
                        }
                      },
                      legend: {},
                      grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                      },
                      xAxis: {
                        type: 'value',
                        boundaryGap: [0, 0.01]
                      },
                      yAxis: {
                        type: 'category',
                        data: averageVerticalChartData.map(obj=>obj.name)
                      },
                      series: [{
                        // name: '2011',
                        type: 'bar',
                        data: averageVerticalChartData.map(obj=>obj.value),
                        label: {
                          show: true, // 显示标签
                          position: "right" // 标签显示在柱形的顶部
                        }
                      }]
                    });
                  }
                </script>
                <!-- End Line Chart -->
<!--爆卡次数-->
                <div id="hotVerticalChart" style="min-height: 400px;" class="echart"></div>
                <script>
                  let hotVerticalChartData;

                  function renderHotVerticalChart(){
                    echarts.init(document.querySelector("#hotVerticalChart")).setOption({
                      title: {
                        text: '爆卡次数(>20)'
                      },
                      tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                          type: 'shadow'
                        }
                      },
                      legend: {},
                      grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                      },
                      xAxis: {
                        type: 'value',
                        boundaryGap: [0, 0.01]
                      },
                      yAxis: {
                        type: 'category',
                        data: hotVerticalChartData.map(obj=>obj.name)
                      },
                      series: [{
                        // name: '2011',
                        type: 'bar',
                        data: hotVerticalChartData.map(obj=>obj.value),
                        label: {
                          show: true, // 显示标签
                          position: "right" // 标签显示在柱形的顶部
                        }
                      }]
                    });
                  }
                </script>
                <!-- End Line Chart -->
<!--爆卡率-->
                <div id="hotRateVerticalChart" style="min-height: 400px;" class="echart"></div>
                <script>
                  let hotRateVerticalChartData;

                  function renderHotRateVerticalChart(){
                    echarts.init(document.querySelector("#hotRateVerticalChart")).setOption({
                      title: {
                        text: '爆卡率'
                      },
                      tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                          type: 'shadow'
                        }
                      },
                      legend: {},
                      grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                      },
                      xAxis: {
                        type: 'value',
                        boundaryGap: [0, 0.01]
                      },
                      yAxis: {
                        type: 'category',
                        data: hotRateVerticalChartData.map(obj=>obj.name)
                      },
                      series: [{
                        // name: '2011',
                        type: 'bar',
                        data: hotRateVerticalChartData.map(obj=>obj.value),
                        label: {
                          show: true,
                          position: "right",
                          formatter: "{c}%"
                        }
                      }]
                    });
                  }
                </script>
                <!-- End Line Chart -->
              </div>
              </div>
            </div><!-- End Reports -->
            <!-- Recent Sales -->
            <div class="col-12">
              <div class="card recent-sales overflow-auto">

                <div class="filter">
                  <a class="icon" href="#" data-bs-toggle="dropdown"><i class="bi bi-three-dots"></i></a>
                  <ul class="dropdown-menu dropdown-menu-end dropdown-menu-arrow">
                    <li class="dropdown-header text-start">
                      <h6>Filter</h6>
                    </li>

                    <li><a class="dropdown-item" href="#">Today</a></li>
                    <li><a class="dropdown-item" href="#">This Month</a></li>
                    <li><a class="dropdown-item" href="#">This Year</a></li>
                  </ul>
                </div>

                <div class="card-body">
                  <h5 class="card-title">Recent Sales <span>| Total</span></h5>

                  <table id="recentSales" class="table table-borderless datatable">
                    <thead>
                      <tr>
                        <th scope="col">Date</th>
                        <th scope="col">Address</th>
                        <th scope="col">Saler</th>
                        <th scope="col">Sold</th>
                        <th scope="col">Fee</th>
                      </tr>
                    </thead>
                    <tbody>

                    </tbody>
                  </table>

                </div>

              </div>
            </div><!-- End Recent Sales -->

            <!-- Top Selling -->
            <div class="col-12">
              <div class="card top-selling overflow-auto">

                <div class="filter">
                  <a class="icon" href="#" data-bs-toggle="dropdown"><i class="bi bi-three-dots"></i></a>
                  <ul class="dropdown-menu dropdown-menu-end dropdown-menu-arrow">
                    <li class="dropdown-header text-start">
                      <h6>Filter</h6>
                    </li>

                    <li><a class="dropdown-item" href="#">Today</a></li>
                    <li><a class="dropdown-item" href="#">This Month</a></li>
                    <li><a class="dropdown-item" href="#">This Year</a></li>
                  </ul>
                </div>

                <div class="card-body pb-0">
                  <h5 class="card-title">Top Selling <span>| Last 30 days</span></h5>

                  <table class="table table-borderless">
                    <thead>
                      <tr>
                        <th scope="col">Date</th>
                        <th scope="col">Address</th>
                        <th scope="col">Saler</th>
                        <th scope="col">Sold</th>
                      </tr>
                    </thead>
                    <tbody>
                      <tr ng-repeat="x in topSelling">
                        <th scope="row">{{x.date}}</th>
                        <td>{{x.addr}}</td>
                        <td>{{x.saler}}</td>
                        <td>{{x.sold}}</td>
                      </tr>
                    </tbody>
                  </table>

                </div>

              </div>
            </div><!-- End Top Selling -->

          </div>
        </div><!-- End Left side columns -->

        <!-- Right side columns -->
        <div class="col-lg-4">

          <!-- Recent Activity -->
          <div class="card">
            <div class="filter">
              <a class="icon" href="#" data-bs-toggle="dropdown"><i class="bi bi-three-dots"></i></a>
              <ul class="dropdown-menu dropdown-menu-end dropdown-menu-arrow">
                <li class="dropdown-header text-start">
                  <h6>Filter</h6>
                </li>

                <li><a class="dropdown-item" href="#">Today</a></li>
                <li><a class="dropdown-item" href="#">This Month</a></li>
                <li><a class="dropdown-item" href="#">This Year</a></li>
              </ul>
            </div>

            <div class="card-body">
              <h5 class="card-title">最近爆卡记录 <span>| 20+</span></h5>

              <div class="activity">

                <div class="activity-item d-flex" ng-repeat="x in hotRecords">
                  <div class="activite-label">{{ x.date }}</div>
                  <i class='bi bi-circle-fill activity-badge text-success align-self-start'></i>
                  <div class="activity-content">
                    {{ x.saler }} 等同学,成功售出 <b>{{x.sold}}</b> 张卡, 地点 {{x.addr}}
                  </div>
                </div><!-- End activity item-->
              </div>

            </div>
          </div><!-- End Recent Activity -->


          <!-- Website Traffic -->
          <div class="card">
            <div class="filter">
              <a class="icon" href="#" data-bs-toggle="dropdown"><i class="bi bi-three-dots"></i></a>
              <ul class="dropdown-menu dropdown-menu-end dropdown-menu-arrow">
                <li class="dropdown-header text-start">
                  <h6>Filter</h6>
                </li>

                <li><a class="dropdown-item" href="#">Today</a></li>
                <li><a class="dropdown-item" href="#">This Month</a></li>
                <li><a class="dropdown-item" href="#">This Year</a></li>
              </ul>
            </div>

            <div class="card-body pb-0">
              <h5 class="card-title">摊点类型售卡数分布 <span>| 总览</span></h5>
              <div id="addressTagChart" style="min-height: 400px;" class="echart"></div>
              <script>
                let addressTagSold;
                let addressTagChartData;
                function renderAddressTagChart(){
                  echarts.init(document.querySelector("#addressTagChart")).setOption({
                    // color: ['#2d90ed', '#eaed2d', '#ed2d2d', '#952ded'],
                    tooltip: {
                      trigger: 'item'
                    },
                    legend: {
                      top: '5%',
                      left: 'center'
                    },
                    series: [{
                      // name: 'Access From',
                      type: 'pie',
                      radius: ['40%', '70%'],
                      avoidLabelOverlap: false,
                      label: {
                        show: false,
                        position: 'center',
                        formatter: "{b} ({d}%)" // 使用 {d}% 显示百分比
                      },
                      emphasis: {
                        label: {
                          show: true,
                          fontSize: '18',
                          fontWeight: 'bold'
                        }
                      },
                      labelLine: {
                        show: false
                      },
                      data:addressTagChartData,
                      label: {
                        show: true,
                        position: "inside",
                        formatter: "{b} : {c} ({d}%)"
                      },
                    }]
                  });
                }
              </script>
            </div>
          </div><!-- End Website Traffic -->
          <!-- Website Traffic -->
          <div class="card">
            <div class="filter">
              <a class="icon" href="#" data-bs-toggle="dropdown"><i class="bi bi-three-dots"></i></a>
              <ul class="dropdown-menu dropdown-menu-end dropdown-menu-arrow">
                <li class="dropdown-header text-start">
                  <h6>Filter</h6>
                </li>

                <li><a class="dropdown-item" href="#">Today</a></li>
                <li><a class="dropdown-item" href="#">This Month</a></li>
                <li><a class="dropdown-item" href="#">This Year</a></li>
              </ul>
            </div>

            <div class="card-body pb-0">
              <h5 class="card-title">摊次售卡数分布 <span>| 总览</span></h5>

              <div id="trafficChart" style="min-height: 400px;" class="echart"></div>
              <script>

                var soldTimesGroup;
                function renderSoldTimesGroup(){
                  echarts.init(document.querySelector("#trafficChart")).setOption({
                    color: ['#2d90ed', '#eaed2d', '#ed2d2d', '#952ded'],
                    tooltip: {
                      trigger: 'item'
                    },
                    legend: {
                      top: '5%',
                      left: 'center'
                    },
                    series: [{
                      name: 'Access From',
                      type: 'pie',
                      radius: ['40%', '70%'],
                      avoidLabelOverlap: false,
                      label: {
                        show: false,
                        position: 'center'
                      },
                      emphasis: {
                        label: {
                          show: true,
                          fontSize: '18',
                          fontWeight: 'bold'
                        }
                      },
                      labelLine: {
                        show: false
                      },
                      data: [{
                        value: soldTimesGroup["blue"],
                        name: '不到10张'
                      },
                        {
                          value: soldTimesGroup["yellow"],
                          name: '10-19'
                        },
                        {
                          value: soldTimesGroup["red"],
                          name: '20-29'
                        },
                        {
                          value: soldTimesGroup["purple"],
                          name: '30+'
                        }
                      ]
                    }]
                  });
                }
              </script>

            </div>
          </div><!-- End Website Traffic -->

        </div><!-- End Right side columns -->

      </div>
    </section>

  </main><!-- End #main -->

  <!-- ======= Footer ======= -->
  <footer id="footer" class="footer">
    <div class="copyright">
      &copy; Copyright <strong><span>Costco</span></strong>. All Rights Reserved
    </div>
    <div class="credits">
      <!-- All the links in the footer should remain intact. -->
      <!-- You can delete the links only if you purchased the pro version. -->
      <!-- Licensing information: https://bootstrapmade.com/license/ -->
      <!-- Purchase the pro version with working PHP/AJAX contact form: https://bootstrapmade.com/nice-admin-bootstrap-admin-html-template/ -->
      Designed by <a href="https://bootstrapmade.com/">BootstrapMade</a>
    </div>
  </footer><!-- End Footer -->

  <a href="#" class="back-to-top d-flex align-items-center justify-content-center"><i class="bi bi-arrow-up-short"></i></a>

  <!-- Vendor JS Files -->
  <script src="assets/vendor/apexcharts/apexcharts.min.js"></script>
  <script src="assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
  <script src="assets/vendor/chart.js/chart.umd.js"></script>

  <script src="assets/vendor/quill/quill.min.js"></script>
  <script src="assets/vendor/simple-datatables/simple-datatables.js"></script>
  <script src="assets/vendor/tinymce/tinymce.min.js"></script>
  <script src="assets/vendor/php-email-form/validate.js"></script>

  <!-- Template Main JS File -->
  <script src="assets/js/main.js"></script>

</body>

</html>
<script>
  var table = simpleTables["recentSales"];

  function filterByDays(datas,days) {
    return datas.filter(item => {
      var date = new Date(item.date);
      var today = new Date();
      var daysAgo = new Date();
      daysAgo.setDate(daysAgo.getDate() - days);
      return date >= daysAgo && date <= today;
    })
  }


  var saleData = []
  var addressData = []
  var app = angular.module('myApp', []);



  app.controller('myCtrl', function($scope, $http, $q) {
    var url1 = './data/saleData.json';
    var url2 = './data/addressPositions.json';

    var request1 = $http.get(url1);
    var request2 = $http.get(url2);

    $q.all([request1, request2]).then(function(responses) {
      saleData = responses[0].data;
      addressData = responses[1].data;
      const weekSold = filterByDays(saleData,7).map(r => parseInt(r.sold) || 0).reduce((acc, curr) => acc + curr, 0)
      const twoWeeksSold = filterByDays(saleData,14).map(r => parseInt(r.sold) || 0).reduce((acc, curr) => acc + curr, 0)
      const threeWeeksSold = filterByDays(saleData,21).map(r => parseInt(r.sold) || 0).reduce((acc, curr) => acc + curr, 0)
      const week2Sold = twoWeeksSold-weekSold
      const week3Sold = threeWeeksSold-twoWeeksSold
      var weekIncrease = (((week2Sold - week3Sold) / week3Sold) * 100).toFixed(0);
      $scope.saleWeek= week2Sold;
      $scope.weekInc= weekIncrease+"%";

      const monthSold = filterByDays(saleData,30).map(r => parseInt(r.sold) || 0).reduce((acc, curr) => acc + curr, 0)
      const twoMonthSold = filterByDays(saleData,60).map(r => parseInt(r.sold) || 0).reduce((acc, curr) => acc + curr, 0)
      const threeMonthSold = filterByDays(saleData,90).map(r => parseInt(r.sold) || 0).reduce((acc, curr) => acc + curr, 0)
      const month2Sold = twoMonthSold-monthSold
      const month3Sold = threeMonthSold-twoMonthSold
      var monthIncrease = (((month2Sold - month3Sold) / month3Sold) * 100).toFixed(0);
      $scope.saleMonth= month2Sold;
      $scope.monthInc= monthIncrease+"%";

      const totalSold = saleData.map(r => parseInt(r.sold) || 0).reduce((acc, curr) => acc + curr, 0)
      $scope.totalSold= totalSold;

      //爆卡记录
      var hotRecords = saleData
              .sort((a, b) => new Date(b.date) - new Date(a.date))
              .filter((item) => item.sold >= 20)
              .slice(0, 6);
      $scope.hotRecords = hotRecords;

      //画图标
      var last28Days = getLastDays(28);
      last28DaySold = last28Days.map(date => {
        return saleData.filter(r => r.date == date).map(r => parseInt(r.sold) || 0).reduce((acc, curr) => acc + curr, 0)
      })
      renderChart()
      //画图标 结束
      //次数饼图
      soldTimesGroup = saleData.reduce((acc, obj) => {
        const sold = obj.sold
        var key =
                (!sold||sold<10)?"blue"
                :sold<20?"yellow"
                :sold<30?"red"
                :"purple";
        if (!acc[key]) {
          acc[key] = 0;
        }
        acc[key]++;
        return acc;
      }, {});
      renderSoldTimesGroup()
      //地点类型饼图

      const addressTagGroup = saleData.reduce((acc, obj) => {
        const sold = parseInt(obj.sold) || 0
        let addr = obj.addr
        let lastIndex = Math.max(addr.indexOf('('), addr.indexOf('（'));
        if (lastIndex !== -1) {
          addr = addr.substring(0, lastIndex);
        }
        var key = "未知";
        addr = addr.trim();
        let addressDatum = addressData[addr];
        if(addressDatum){
          var tags = addressDatum["tag"].split(";")
          key = tags[0]
        }else{
          console.log(addr);
        }
        if(key === '房地产' && tags.length>1){
          key = tags[1]
        }
        if(key === '公司企业' || key === '写字楼'){
          key = "写字楼/企业"
        }
        if(key === '公司企业' || key === '写字楼'){
          key = "写字楼/企业"
        }
        if (!acc[key]) {
          acc[key] = {"times":0,"sold":0,"hot":0};
        }
        acc[key]["times"]++;
        acc[key]["sold"]+=sold;
        if (sold>=20){
          acc[key]["hot"]++;
        }
        return acc;
      }, {});
      addressTagCountArr = Object.entries(addressTagGroup).map(([key, value]) => {
        return { key, value };
      });
      addressTagCountArr.sort((a, b) => b.value.sold - a.value.sold);
      addressTagSold = addressTagCountArr.map(ele => {
        return {"name":ele.key, "value":ele.value.sold};
      });
      addressTagChartData = topChartData(addressTagSold,7);
      verticalBarChartData = topChartData(addressTagSold,10).reverse();
      averageVerticalChartData = topChartData(addressTagCountArr.filter(ele => ele.value.times>10).map(ele => {
        return {"name":ele.key, "value":(parseFloat(ele.value.sold)/ele.value.times).toFixed(1)};
      }),10).reverse();
      hotVerticalChartData = topChartData(addressTagCountArr.map(ele => {
        return {"name":ele.key, "value":ele.value.hot};
      }),10).reverse();
      hotRateVerticalChartData = topChartData(addressTagCountArr.filter(ele => ele.value.times>10).map(ele => {
        return {"name":ele.key, "value":(parseFloat(ele.value.hot)*100/ele.value.times).toFixed(1)};
      }),10).reverse();
      renderAddressTagChart()
      renderVerticalBarChart()
      renderAverageVerticalChart()
      renderHotVerticalChart()
      renderHotRateVerticalChart()

      //最近销售记录
      var recentSale = []
      saleData.forEach(function(r) {
        if(!r.date || !r.addr || !r.sold || r.sold<=0 || !r.saler){
          return;
        }
        r.Date=r.date;
        r.Address=r.addr;
        r.Sold=r.sold;
        r.Saler=r.saler;
        r.Fee=r.fee;
        recentSale.push(r);
      });

      table.insert(recentSale);
      //topSelling
      $scope.topSelling=filterByDays(saleData,30).sort(function(a, b) {
        return b.sold - a.sold;
      }).slice(0, 6);

    }, function errorCallback(response) {
      // 请求失败执行代码
    });
  });

  function getLastDays(days) {
    var today = new Date();
    var dates = [];
    for (var i = 0; i < days; i++) {
      var date = new Date();
      date.setDate(today.getDate() - i);
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      var day = date.getDate();
      var formattedDate = year + '/' + month + '/' + day;
      dates.push(formattedDate);
    }
    return dates.reverse(); // 反转日期列表
  }
  function getLast7DaysOfWeek() {
    var weekdays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
    var dates = [];
    for (var i = 0; i < 7; i++) {
      var date = new Date();
      date.setDate(date.getDate() - i);
      var weekday = weekdays[date.getDay()];
      dates.push(weekday);
    }
    return dates.reverse(); // 反转星期列表
  }
  function topChartData(data, num){
    data.sort((a, b) => b.value - a.value);
    const top7Data = data.slice(0, num);

    const otherSum = data.slice(num).reduce((sum, item) => sum + item.value, 0);
    const otherData = { name: "其他", value: otherSum };
    return [...top7Data, otherData];
  }



</script>